from rest_framework import serializers
from apps.app01.models import Product, Config

class ConfigSerializer(serializers.ModelSerializer):
    class Meta:
        model = Config
        fields = ['name', 'choices', 'default', 'price']

class ProductDetailSerializer(serializers.ModelSerializer):
    productId = serializers.IntegerField(source='id')
    picUrl = serializers.CharField(source='pic_url')
    config = ConfigSerializer(many=True, read_only=True, source='configs')
    class Meta:
        model = Product
        fields = ['productId', 'name', 'brief', 'picUrl', 'price', 'config']